package fenetres;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

import controles.AccueilMenuAction;
import controles.AddProductAction;

import modeles.*;


public class Accueil extends JFrame implements ActionListener{
	JFrame fenetrePrinc;
	JMenuBar menuPrincipal;
	public JMenuItem connexMenu,deconnexMenu,exitMenu,addProdMenu,updateProdMenu,listProdMenu,infoStockMenu,addProdStockMenu,traceStockMenu,bcClientMenu,factCientMenu,addFrsMenu,updateFrsMenu,bcFrsMenu;
	JPanel entetePanel,imagePanel;
	
	String login,mdp;
	public JDesktopPane desktop;
	public Utilisateur userConnected;
	public AuthentificationFrame authent;
	static Accueil accueil;
	public Accueil(){
		super("InternalFrameDemo");
		
		System.setProperty(
	            "Quaqua.tabLayoutPolicy","wrap"

	         );

	         // set the Quaqua Look and Feel in the UIManager
	         try {
	              UIManager.setLookAndFeel(ch.randelshofer.quaqua.QuaquaManager.getLookAndFeel());
	         // set UI manager properties here that affect Quaqua
	         
	         } 
	         catch (Exception e) {
	             // take an appropriate action here
	             
	         }
	        
	    //authent = new AuthentificationFrame(this);
		fenetrePrinc = new JFrame();
		entetePanel = new JPanel();
		entetePanel.setBounds(0,0,900,100);
		entetePanel.setBackground(Color.white);
		entetePanel.setOpaque(true);
		imagePanel = new JPanel();
		imagePanel.setBounds(0,100,900,800);
		
		etablishMenu();
		etablishEntete();
		etablishImage();
		
		
		desktop = new JDesktopPane(); //a specialized layered pane

		fenetrePrinc.setContentPane(desktop);

        //Make dragging a little faster but perhaps uglier.
        desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
		fenetrePrinc.getContentPane().setLayout(null);
		fenetrePrinc.getContentPane().add(entetePanel);
		fenetrePrinc.getContentPane().add(imagePanel);
		fenetrePrinc.setTitle("Plateforme de Gestion de Stock d'un restaurant");
		fenetrePrinc.setBounds(250,40,900,700);
		fenetrePrinc.setSize(900,700);
		fenetrePrinc.getContentPane().setBackground(Color.LIGHT_GRAY);
		//recuperation de la taille de la fenetre
		//Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
		//fenetrePrinc.setLocation((screen.width - this.getSize().width)/2,(screen.height - this.getSize().height)/2);
		
		fenetrePrinc.setJMenuBar(menuPrincipal);
		fenetrePrinc.setVisible(true);
		fenetrePrinc.setResizable(false);
        
	}
	
	
	
	public void etablishEntete(){
		JLabel enteteLab  = new JLabel ("Plateforme de Gestion de stock restaurant");
		enteteLab.setFont(new java.awt.Font("Century Schoolbook L", java.awt.Font.BOLD, 22));
		enteteLab.setForeground(new Color(12,59,234));
		enteteLab.setBounds(150,30,600,20);
		
		entetePanel.setLayout(null);
		entetePanel.add(enteteLab);
	}
	
	public void etablishMenu(){
		//Menu principal
		menuPrincipal = new JMenuBar ();
		//menu fichier
		JMenu fileMenu = new JMenu("Fichier");
		connexMenu = new JMenuItem("Connecter");
		connexMenu.addActionListener(new AccueilMenuAction(this));
		deconnexMenu = new JMenuItem("Deconnecter");
		deconnexMenu.addActionListener(new AccueilMenuAction(this));
		exitMenu = new JMenuItem("Quitter");
		exitMenu.addActionListener(new AccueilMenuAction(this));
		
		//menu produit
		JMenu prodMenu = new JMenu("Produit");
		addProdMenu = new JMenuItem("Ajouter Produit");
		addProdMenu.addActionListener(new AccueilMenuAction(this));
		updateProdMenu = new JMenuItem("Modifier Produit");
		updateProdMenu.addActionListener(new AccueilMenuAction(this));
		listProdMenu = new JMenuItem("Lister Produit");
		listProdMenu.addActionListener(new AccueilMenuAction(this));
		
		//menu stock
		JMenu stockMenu = new JMenu("Stock");
		infoStockMenu = new JMenuItem("Information sur les stocks");
		infoStockMenu.addActionListener(new AccueilMenuAction(this));
		addProdStockMenu = new JMenuItem("Entrer produit en stock");
		addProdStockMenu.addActionListener(new AccueilMenuAction(this));
		traceStockMenu = new JMenuItem("trace des operations");
		traceStockMenu.addActionListener(new AccueilMenuAction(this));
		
		//menu Clients
		JMenu clientMenu = new JMenu("Vente");
		bcClientMenu = new JMenuItem("Elaborer BC Client");
		bcClientMenu.addActionListener(new AccueilMenuAction(this));
		factCientMenu = new JMenuItem("Elaborer Facture Client");
		factCientMenu.addActionListener(new AccueilMenuAction(this));
		
		
		//Menu Fournisseurs
		JMenu frsMenu = new JMenu("Fournisseurs");
		addFrsMenu = new JMenuItem("Ajouter Fournisseur");
		addFrsMenu.addActionListener(new AccueilMenuAction(this));
		updateFrsMenu = new JMenuItem("Modifier Fournisseur");
		updateFrsMenu.addActionListener(new AccueilMenuAction(this));
		bcFrsMenu = new JMenuItem("Elaborer BC Fournisseurs");
		bcFrsMenu.addActionListener(this);
		
		fileMenu.add(connexMenu);
		fileMenu.add(deconnexMenu);
		fileMenu.add(exitMenu);
		
		prodMenu.add(addProdMenu);
		prodMenu.add(updateProdMenu);
		prodMenu.add(listProdMenu);
		
		stockMenu.add(infoStockMenu);
		stockMenu.add(addProdStockMenu);
		stockMenu.add(traceStockMenu);
		
		clientMenu.add(bcClientMenu);
		clientMenu.add(factCientMenu);
		
		frsMenu.add(addFrsMenu);
		frsMenu.add(updateFrsMenu);
		frsMenu.add(bcFrsMenu);
		
		
		menuPrincipal.add(fileMenu);
		menuPrincipal.add(prodMenu);
		menuPrincipal.add(stockMenu);
		menuPrincipal.add(clientMenu);
		menuPrincipal.add(frsMenu);
	}
	public void etablishImage(){
		JLabel imageLab = null;
		JLabel imageLab1 = null;
		JLabel imageLab2 = null;
		
		try {
			BufferedImage picture = ImageIO.read(new File("images/fond2.jpg"));
			imageLab = new JLabel (new ImageIcon(picture));
			
			BufferedImage picture1 = ImageIO.read(new File("images/fond4.jpg"));
			imageLab1 = new JLabel (new ImageIcon(picture1));
			
			BufferedImage picture2 = ImageIO.read(new File("images/fond5.jpg"));
			imageLab2 = new JLabel (new ImageIcon(picture2));
		} catch (IOException e) {
			e.printStackTrace();
		}
		imageLab.setBounds(40,10,400,300);
		imageLab1.setBounds(470,10,360,500);
		imageLab2.setBounds(60,300,350,250);
		imagePanel.setLayout(null);
		imagePanel.add(imageLab);
		imagePanel.add(imageLab1);
		imagePanel.add(imageLab2);
	}

	public static void main(String argv[]){
		
		accueil = new Accueil();
	}
	
	

	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		}
}
